{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-21T03:07:37.388060Z",
     "start_time": "2020-10-21T03:07:37.083303Z"
    }
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "import numpy as np\n",
    "import torch.nn.functional as F\n",
    "import  matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-21T03:43:43.106875Z",
     "start_time": "2020-10-21T03:43:43.090778Z"
    }
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "from_numpy() takes no keyword arguments",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                              Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-28-69bc0b76da1a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0mm\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mview\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m15\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0mnpa\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mones\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mtnpa\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_numpy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnpa\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mrequire_grad\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m: from_numpy() takes no keyword arguments"
     ]
    }
   ],
   "source": [
    "result=torch.ones(3,4,5)\n",
    "rm=result.mean()\n",
    "m=result.view(-1,15)\n",
    "npa=np.ones((4,5,2))\n",
    "tnpa=torch.from_numpy(npa)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-21T03:45:26.746099Z",
     "start_time": "2020-10-21T03:45:26.742736Z"
    }
   },
   "outputs": [],
   "source": [
    "use_tensor=torch.ones(3,4,5,requires_grad=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-21T03:51:13.235811Z",
     "start_time": "2020-10-21T03:51:13.222259Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[ 1.,  2.,  3.,  4.,  5.],\n",
      "         [ 6.,  7.,  8.,  9., 10.],\n",
      "         [11., 12., 13., 14., 15.],\n",
      "         [16., 17., 18., 19., 20.]],\n",
      "\n",
      "        [[21., 22., 23., 24., 25.],\n",
      "         [26., 27., 28., 29., 30.],\n",
      "         [31., 32., 33., 34., 35.],\n",
      "         [36., 37., 38., 39., 40.]],\n",
      "\n",
      "        [[41., 42., 43., 44., 45.],\n",
      "         [46., 47., 48., 49., 50.],\n",
      "         [51., 52., 53., 54., 55.],\n",
      "         [56., 57., 58., 59., 60.]]], requires_grad=True)\n"
     ]
    }
   ],
   "source": [
    "nama=torch.Tensor([i for i in range(1,61)])\n",
    "nama1=nama.view(3,4,5)\n",
    "nama1.requires_grad=True\n",
    "print(nama1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-21T03:51:46.019205Z",
     "start_time": "2020-10-21T03:51:46.014860Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n"
     ]
    }
   ],
   "source": [
    "print(nama1.grad_fn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-21T03:52:01.954103Z",
     "start_time": "2020-10-21T03:52:01.946109Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor(30.5000, grad_fn=<MeanBackward0>)"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nama1.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-21T03:58:08.679910Z",
     "start_time": "2020-10-21T03:58:08.675986Z"
    }
   },
   "outputs": [],
   "source": [
    "z=nama1*2\n",
    "z=z.mean()\n",
    "z.backward()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
